package com.cjy.common.utils.tag;

import com.cjy.common.utils.ApplicationUtils;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.components.Component;
import org.apache.struts2.views.jsp.ui.TextFieldTag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * input tag :<xx:input id="..." authId="...authId.."/>
 * the authId is required
 * @author jay.zhoujingjie
 *         Date: 13-12-14
 *         Time: 上午11:03
 */

public class InputTag extends TextFieldTag
{
	// 权限key
	private String	authKey;
	private String	placeholder;
	
	public String getAuthKey()
	{
		return authKey;
	}
	
	@Override
	public Component getBean(ValueStack stack,HttpServletRequest req,HttpServletResponse res)
	{
		return new InputTagBean(stack, req, res);
	}
	
	public String getPlaceholder()
	{
		return placeholder;
	}
	
	@Override
	protected void populateParams()
	{
		if(disabled != null)
		{
			if("disabled".equals(disabled))
			{
				disabled = "true";
			}
		}
		if(id == null)
		{
			id = "";
		}
		super.populateParams();
		InputTagBean input = (InputTagBean) component;
		input.setVisible(ApplicationUtils.isAllowAsThisAction(authKey));
		input.setPlaceholder(placeholder);
		
	}
	
	public void setAuthKey(String authKey)
	{
		this.authKey = authKey;
	}
	
	public void setPlaceholder(String placeholder)
	{
		this.placeholder = placeholder;
	}
}
